package ctrlLayer;

import java.util.ArrayList;

import modelLayer.*;
import dbLayer.*;

public class SltCtrl {
	private static SltCtrl instance;
	private Subject s;
	private Level l;
	private Topic t;
	private SubjectDb subDb;
	private LevelDb levelDb;
	private TopicDb topicDb;
	
	private SltCtrl(){
		subDb = new SubjectDb();
		levelDb = new LevelDb();
		topicDb = new TopicDb();
	}
	
	public static SltCtrl getInstance(){
		if(instance == null){
			instance = new SltCtrl();			
		}
		return instance;
	}
	
	public void createSubject(String subject) throws Exception{
		s = new Subject();
		s.setSubject(subject);
		subDb.insertSubject(s);
	}
	
	public Subject findSubject(String subject){
		return subDb.findSubject(subject);
	}
	
	public Subject findSubject(int sNo){
		return subDb.findSubject(sNo);
	}
	
	public ArrayList<Subject> listSubjects(){
		return subDb.findAllSubjects();
	}
	
	public void createLevel(String level, int sNo) throws Exception{
		l = new Level();
		l.setLevel(level);
		levelDb.insertLevel(l, sNo);
	}
	
	public Level findLevel(String level){
		return levelDb.findLevel(level);
	}
	
	public Level findLevel(int lNo){
		return levelDb.findLevel(lNo);
	}
	
	public ArrayList<Level> listLevels(){
		return levelDb.findAllLevels();
	}
	
	public ArrayList<Level> listLevelsBySNo(int sNo){
		return levelDb.findLevelBySNo(sNo);
	}
	
	public void createtopic(String topic, int lNo) throws Exception{
		t = new Topic();
		t.setTopic(topic);
		topicDb.insertTopic(t, lNo);
	}
	
	public Topic findTopic(String topic){
		return topicDb.findTopic(topic);
	}
	
	public Topic findTopic(int tNo){
		return topicDb.findTopic(tNo);
	}
	
	public ArrayList<Topic> listTopics(){
		return topicDb.findAllTopics();
	}
	
	public ArrayList<Topic> listTopicsByLNo(int lNo){
		return topicDb.findTopicByLNo(lNo);
	}

}
